package com.everest.tribalapp;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Dering_Pengelola_5 extends Activity implements OnClickListener
{

	
	private Button next;
	protected String message;
	private Button previous;
	private CheckBox checkBox_2a5;
	private CheckBox checkBox_2b5;
	private CheckBox checkBox_2c5;
	private CheckBox checkBox_2d5;
	private CheckBox checkBox_3a5;
	private CheckBox checkBox_3b5;
	private CheckBox checkBox_3c5;
	private CheckBox checkBox_3d5;
	private CheckBox checkBox_3e5;
	private CheckBox checkBox_3f5;
	private CheckBox checkBox_4a5;
	private CheckBox checkBox_4b5;
	private CheckBox checkBox_4c5;
	private CheckBox checkBox_4d5;
	private EditText dering_f5_ans_1;
	private EditText dering_f5_ans_2e;
	private EditText dering_f5_ans_3g;
	
	
	private TextView dering_peng_q5_1;
	private TextView dering_peng_q5_2;
	private TextView dering_peng_q5_2e;
	private TextView dering_peng_q5_3;
	private TextView dering_f5_qes_5;
	private TextView dering_peng_q5_3g;
	private TextView dering_peng_q5_4;
	
	private int flag=0;
	protected int id;
	protected String[] choice;
	protected String selectvalue;

	private String value;
	private CharSequence[] MSG_VALUES_1={"Ya, Ada","Tidak Ada -> Lanjut ke No VI-1","Tidak Tahu -> Lanjut ke No VI-1"};
	private CharSequence[] MSG_VALUES_2={"Penyedia jasa","Aparat pemerintah daerah (Kab/Kec/Desa)","Kementerian Kominfo","Lainnya"};
	private CharSequence[] MSG_VALUES_3={"Pertemuan informal (pengajian, arisan, dll) ","Pertemuan formal","Media cetak (Koran, majalah, tabloid, selebaran) ","Media elektronik (radio, TV) ","Spanduk, papan pengumuman" ,"Lainnya"};
	private CharSequence[] MSG_VALUES_4={"Program pembangunan fasilitas telepon USO","Manfaat dan fungsi layanan ","Status kepemilikan perangkat dan pengelolaan","Pentarifan"};

	protected boolean[] selectVal2={false,false,false,false};
	protected boolean[] selectVal3={false,false,false,false,false,false};
	protected boolean[] selectVal4={false,false,false,false};
	@Override
	public void onBackPressed() 
	{
		
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Dering_Pengelola_5.this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.dering_pengelola_5);
		
		 initialization();
	

previous.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View v) {
		Intent in=new Intent(getApplicationContext(),Dering_Pengelola_4.class);
		startActivity(in);
		Dering_Pengelola_5.this.finish();
	}
});

		 next.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					Intent in=new Intent(getApplicationContext(),Dering_Pengelola_6.class);
					startActivity(in);
					Dering_Pengelola_5.this.finish();
				}
			});
		
		
	}

	private void initialization() {

		dering_peng_q5_1=(TextView)findViewById(R.id.dering_peng_q5_1);
		dering_peng_q5_2=(TextView)findViewById(R.id.dering_peng_q5_2);
		dering_peng_q5_2e=(TextView)findViewById(R.id.dering_peng_q5_2e);
		dering_peng_q5_3=(TextView)findViewById(R.id.dering_peng_q5_3);
		dering_peng_q5_3g=(TextView)findViewById(R.id.dering_peng_q5_3g);
		dering_peng_q5_4=(TextView)findViewById(R.id.dering_peng_q5_4);
		
		
		dering_f5_ans_1=(EditText)findViewById(R.id.dering_f5_ans_1);
		dering_f5_ans_2e=(EditText)findViewById(R.id.dering_f5_ans_2e);
		dering_f5_ans_3g=(EditText)findViewById(R.id.dering_f5_ans_3g);
	
		
		
		checkBox_2a5=(CheckBox)findViewById(R.id.checkBox_2a5);
		checkBox_2b5=(CheckBox)findViewById(R.id.checkBox_2b5);
		checkBox_2c5=(CheckBox)findViewById(R.id.checkBox_2c5);
		checkBox_2d5=(CheckBox)findViewById(R.id.checkBox_2d5);
		checkBox_3a5=(CheckBox)findViewById(R.id.checkBox_3a5);
		checkBox_3b5=(CheckBox)findViewById(R.id.checkBox_3b5);
		checkBox_3c5=(CheckBox)findViewById(R.id.checkBox_3c5);
		checkBox_3d5=(CheckBox)findViewById(R.id.checkBox_3d5);
		checkBox_3e5=(CheckBox)findViewById(R.id.checkBox_3e5);
		checkBox_3f5=(CheckBox)findViewById(R.id.checkBox_3f5);
		checkBox_4a5=(CheckBox)findViewById(R.id.checkBox_4a5);
		checkBox_4b5=(CheckBox)findViewById(R.id.checkBox_4b5);
		checkBox_4c5=(CheckBox)findViewById(R.id.checkBox_4c5);
		checkBox_4d5=(CheckBox)findViewById(R.id.checkBox_4d5);
		
	
		
		next=(Button)findViewById(R.id.next);
		previous=(Button)findViewById(R.id.previous);
		dering_peng_q5_1.setOnClickListener(this);
		dering_peng_q5_2.setOnClickListener(this);
		dering_peng_q5_2e.setOnClickListener(this);
		dering_peng_q5_3.setOnClickListener(this);
		dering_peng_q5_3g.setOnClickListener(this);
		dering_peng_q5_4.setOnClickListener(this);
		dering_f5_ans_1.setOnClickListener(this);
		checkBox_2a5.setOnClickListener(this);
		checkBox_2b5.setOnClickListener(this);
		checkBox_2c5.setOnClickListener(this);
		checkBox_2d5.setOnClickListener(this);
		checkBox_3a5.setOnClickListener(this);
		checkBox_3b5.setOnClickListener(this);
		checkBox_3c5.setOnClickListener(this);
		checkBox_3d5.setOnClickListener(this);
		checkBox_3e5.setOnClickListener(this);
		checkBox_3f5.setOnClickListener(this);
		checkBox_4a5.setOnClickListener(this);
		checkBox_4b5.setOnClickListener(this);
		checkBox_4c5.setOnClickListener(this);
		checkBox_4d5.setOnClickListener(this);
		dering_f5_ans_1.setFocusable(false);
				
	}

	@Override
	public void onClick(View v) 
	{
		if(v.getId()==dering_peng_q5_1.getId())
		{
			value=getResources().getString(R.string.dering_peng_q5_1);
			toast_msg();
		}
		else if(v.getId()==dering_peng_q5_2.getId())
		{
			value=getResources().getString(R.string.dering_peng_q5_2);
			toast_msg();
		}
		else if(v.getId()==dering_peng_q5_2e.getId())
		{
			value=getResources().getString(R.string.dering_peng_q5_2e);
			toast_msg();
		}
		else if(v.getId()==dering_peng_q5_3.getId())
		{
			value=getResources().getString(R.string.dering_peng_q5_3);
			toast_msg();
		}
		else if(v.getId()==dering_peng_q5_3g.getId())
		{
			value=getResources().getString(R.string.dering_peng_q5_3g);
			toast_msg();
		}
		else if(v.getId()==dering_peng_q5_4.getId())
		{
			value=getResources().getString(R.string.dering_peng_q5_4);
			toast_msg();
		}

		//answer/combobox disini//
		else if(v.getId()==dering_f5_ans_1.getId())
		{
			msg_f5_ans_1();
		}
		//checkbox//
		else if(v.getId()==checkBox_2a5.getId())
		{
			checkBox_2a5.setChecked(false);
			msg_f5_ans_2();
		}
		else if(v.getId()==checkBox_2b5.getId())
		{
			checkBox_2b5.setChecked(false);
			msg_f5_ans_2();
		}
		else if(v.getId()==checkBox_2c5.getId())
		{
			checkBox_2c5.setChecked(false);
			msg_f5_ans_2();
		}
		else if(v.getId()==checkBox_2d5.getId())
		{
			checkBox_2d5.setChecked(false);
			msg_f5_ans_2();
		}
		else if(v.getId()==checkBox_3a5.getId())
		{
			checkBox_3a5.setChecked(false);
			msg_f5_ans_3();
		}
		else if(v.getId()==checkBox_3b5.getId())
		{
			checkBox_3b5.setChecked(false);
			msg_f5_ans_3();
		}
		else if(v.getId()==checkBox_3c5.getId())
		{
			checkBox_3c5.setChecked(false);
			msg_f5_ans_3();
		}
		else if(v.getId()==checkBox_3d5.getId())
		{
			checkBox_3d5.setChecked(false);
			msg_f5_ans_3();
		}
		else if(v.getId()==checkBox_3e5.getId())
		{
			checkBox_3e5.setChecked(false);
			msg_f5_ans_3();
		}
		else if(v.getId()==checkBox_3f5.getId())
		{
			checkBox_3f5.setChecked(false);
			msg_f5_ans_3();
		}
		else if(v.getId()==checkBox_4a5.getId())
		{
			checkBox_4a5.setChecked(false);
			msg_f5_ans_4();
		}
		else if(v.getId()==checkBox_4b5.getId())
		{
			checkBox_4b5.setChecked(false);
			msg_f5_ans_4();
		}
		else if(v.getId()==checkBox_4c5.getId())
		{
			checkBox_4c5.setChecked(false);
			msg_f5_ans_4();
		}
		else if(v.getId()==checkBox_4d5.getId())
		{
			checkBox_4d5.setChecked(false);
			msg_f5_ans_4();
		}
	}
	
	public void toast_msg()
	{
		LayoutInflater inflater = getLayoutInflater();

		View layout = inflater.inflate(R.layout.custom_toast,
				(ViewGroup) findViewById(R.id.custom_toast_layout_id));
		TextView text = (TextView) layout.findViewById(R.id.text);
		text.setText(value);
		Toast toast = new Toast(getApplicationContext());
		toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
		toast.setDuration(Toast.LENGTH_LONG);
		toast.setView(layout);
		toast.show();
	}
	private void msg_f5_ans_1() {
	     Builder builder = new AlertDialog.Builder(this);
	     builder.setTitle("Select");
	     builder.setSingleChoiceItems(MSG_VALUES_1, -1, new DialogInterface.OnClickListener() {
	       

		@Override
	       public void onClick(DialogInterface dialog, int which) {
			 dering_f5_ans_1.setText(""+(which+1));
	         dialog.dismiss();
	         
	       }
	     });
	     builder.setNegativeButton("cancel",
	         new DialogInterface.OnClickListener() {
	           @Override
	           public void onClick(DialogInterface dialog, int which) {
	             dialog.dismiss();
	           }
	         });
	     AlertDialog alert = builder.create();
	     alert.show();
	   }
	private void msg_f5_ans_2()
	   {
		     Builder builder = new AlertDialog.Builder(this);
		     builder.setTitle("Answer");
		     builder.setMultiChoiceItems(MSG_VALUES_2, selectVal2,
		         new DialogInterface.OnMultiChoiceClickListener()
		     {
		           @Override
		           public void onClick(DialogInterface dialog, int which,
		               boolean isChecked) 
		           {
		             selectVal2[which] = isChecked;
		           }
		         });
		     builder.setPositiveButton("Set", new DialogInterface.OnClickListener() {
		       @Override
		       public void onClick(DialogInterface dialog, int which) {
		         for (int i = 0; i <MSG_VALUES_2.length; i++) 
		         {
		           if (selectVal2[i]) 
		           {
		              if(i==0)
		 				{
		            	 
		            	  checkBox_2a5.setChecked(true);
	 					}
		 				else if(i==1)
		 				{
		 					checkBox_2b5.setChecked(true);
		 				}
		 				else if(i==2)
		 				{
		 					checkBox_2c5.setChecked(true);
		 				}
		 				else if(i==3)
		 				{
		 					checkBox_2d5.setChecked(true);
		 				}
		           }
		           else
		           {
		        	   if(i==0)
		 				{
		            	 
		        		   checkBox_2a5.setChecked(false);
	 					}
		 				else if(i==1)
		 				{
		 					checkBox_2b5.setChecked(false);
		 				}
		 				else if(i==2)
		 				{
		 					checkBox_2c5.setChecked(false);
		 				}
		 				else if(i==3)
		 				{
		 					checkBox_2d5.setChecked(false);
		 				}
		 				
		           }
		         }
		        }
		     });
		     builder.setNegativeButton("cancel",
		         new DialogInterface.OnClickListener() {
		           @Override
		           public void onClick(DialogInterface dialog, int which) {
		             dialog.dismiss();
		           }
		         });
		     AlertDialog alert = builder.create();
		     alert.show();
		   }
	private void msg_f5_ans_3()
	   {
		     Builder builder = new AlertDialog.Builder(this);
		     builder.setTitle("Answer");
		     builder.setMultiChoiceItems(MSG_VALUES_3, selectVal3,
		         new DialogInterface.OnMultiChoiceClickListener()
		     {
		           @Override
		           public void onClick(DialogInterface dialog, int which,
		               boolean isChecked) 
		           {
		             selectVal3[which] = isChecked;
		           }
		         });
		     builder.setPositiveButton("Set", new DialogInterface.OnClickListener() {
		       @Override
		       public void onClick(DialogInterface dialog, int which) {
		         for (int i = 0; i <MSG_VALUES_3.length; i++) 
		         {
		           if (selectVal3[i]) 
		           {
		              if(i==0)
		 				{
		            	 
		            	  checkBox_3a5.setChecked(true);
	 					}
		 				else if(i==1)
		 				{
		 					checkBox_3b5.setChecked(true);
		 				}
		 				else if(i==2)
		 				{
		 					checkBox_3c5.setChecked(true);
		 				}
		 				else if(i==3)
		 				{
		 					checkBox_3d5.setChecked(true);
		 				}
		 				else if(i==4)
		 				{
		 					checkBox_3e5.setChecked(true);
		 				}
		 				else if(i==5)
		 				{
		 					checkBox_3f5.setChecked(true);
		 				}
		           }
		           else
		           {
		        	   if(i==0)
		 				{
		            	 
		        		   checkBox_3a5.setChecked(false);
	 					}
		 				else if(i==1)
		 				{
		 					checkBox_3b5.setChecked(false);
		 				}
		 				else if(i==2)
		 				{
		 					checkBox_3c5.setChecked(false);
		 				}
		 				else if(i==3)
		 				{
		 					checkBox_3d5.setChecked(false);
		 				}
		 				else if(i==4)
		 				{
		 					checkBox_3e5.setChecked(false);
		 				}
		 				else if(i==5)
		 				{
		 					checkBox_3f5.setChecked(false);
		 				}
		           }
		         }
		        }
		     });
		     builder.setNegativeButton("cancel",
		         new DialogInterface.OnClickListener() {
		           @Override
		           public void onClick(DialogInterface dialog, int which) {
		             dialog.dismiss();
		           }
		         });
		     AlertDialog alert = builder.create();
		     alert.show();
		   }
	private void msg_f5_ans_4()
	   {
		     Builder builder = new AlertDialog.Builder(this);
		     builder.setTitle("Answer");
		     builder.setMultiChoiceItems(MSG_VALUES_4, selectVal4,
		         new DialogInterface.OnMultiChoiceClickListener()
		     {
		           @Override
		           public void onClick(DialogInterface dialog, int which,
		               boolean isChecked) 
		           {
		             selectVal4[which] = isChecked;
		           }
		         });
		     builder.setPositiveButton("Set", new DialogInterface.OnClickListener() {
		       @Override
		       public void onClick(DialogInterface dialog, int which) {
		         for (int i = 0; i <MSG_VALUES_4.length; i++) 
		         {
		           if (selectVal4[i]) 
		           {
		              if(i==0)
		 				{
		            	 
		            	  checkBox_4a5.setChecked(true);
	 					}
		 				else if(i==1)
		 				{
		 					checkBox_4b5.setChecked(true);
		 				}
		 				else if(i==2)
		 				{
		 					checkBox_4c5.setChecked(true);
		 				}
		 				else if(i==3)
		 				{
		 					checkBox_4d5.setChecked(true);
		 				}
		           }
		           else
		           {
		        	   if(i==0)
		 				{
		            	 
		        		   checkBox_4a5.setChecked(false);
	 					}
		 				else if(i==1)
		 				{
		 					checkBox_4b5.setChecked(false);
		 				}
		 				else if(i==2)
		 				{
		 					checkBox_4c5.setChecked(false);
		 				}
		 				else if(i==3)
		 				{
		 					checkBox_4d5.setChecked(false);
		 				}
		 				
		           }
		         }
		        }
		     });
		     builder.setNegativeButton("cancel",
		         new DialogInterface.OnClickListener() {
		           @Override
		           public void onClick(DialogInterface dialog, int which) {
		             dialog.dismiss();
		           }
		         });
		     AlertDialog alert = builder.create();
		     alert.show();
		   }
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		SharedPreferences preferences=getSharedPreferences("dering_f5_details",MODE_PRIVATE);
		SharedPreferences.Editor editor=preferences.edit();
		editor.putString("5_1", dering_f5_ans_1.getText().toString().trim());
		editor.putBoolean("5_2a",checkBox_2a5.isChecked());
		editor.putBoolean("5_2b",checkBox_2b5.isChecked());
		editor.putBoolean("5_2c",checkBox_2c5.isChecked());
		editor.putBoolean("5_2d",checkBox_2d5.isChecked());
		editor.putString("5_2e", dering_f5_ans_2e.getText().toString().trim());
		editor.putBoolean("5_3a",checkBox_3a5.isChecked());
		editor.putBoolean("5_3b",checkBox_3b5.isChecked());
		editor.putBoolean("5_3c",checkBox_3c5.isChecked());
		editor.putBoolean("5_3d",checkBox_3d5.isChecked());
		editor.putBoolean("5_3e",checkBox_3e5.isChecked());
		editor.putBoolean("5_3f",checkBox_3f5.isChecked());
		editor.putString("5_3g", dering_f5_ans_3g.getText().toString().trim());
		editor.putBoolean("5_4a",checkBox_4a5.isChecked());
		editor.putBoolean("5_4b",checkBox_4b5.isChecked());
		editor.putBoolean("5_4c",checkBox_4c5.isChecked());
		editor.putBoolean("5_4d",checkBox_4d5.isChecked());
		editor.commit();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		SharedPreferences preferences=getSharedPreferences("dering_f5_details",MODE_PRIVATE);
		dering_f5_ans_1.setText(preferences.getString("5_1",""));
		dering_f5_ans_2e.setText(preferences.getString("5_2e",""));
		dering_f5_ans_3g.setText(preferences.getString("5_3g",""));
		checkBox_2a5.setChecked(preferences.getBoolean("5_2a",false));
		checkBox_2b5.setChecked(preferences.getBoolean("5_2b",false));
		checkBox_2c5.setChecked(preferences.getBoolean("5_2c",false));
		checkBox_2d5.setChecked(preferences.getBoolean("5_2d",false));
		checkBox_3a5.setChecked(preferences.getBoolean("5_3a",false));
		checkBox_3b5.setChecked(preferences.getBoolean("5_3b",false));
		checkBox_3c5.setChecked(preferences.getBoolean("5_3c",false));
		checkBox_3d5.setChecked(preferences.getBoolean("5_3d",false));
		checkBox_3e5.setChecked(preferences.getBoolean("5_3e",false));
		checkBox_3f5.setChecked(preferences.getBoolean("5_3f",false));
		checkBox_4a5.setChecked(preferences.getBoolean("5_4a",false));
		checkBox_4b5.setChecked(preferences.getBoolean("5_4b",false));
		checkBox_4c5.setChecked(preferences.getBoolean("5_4c",false));
		checkBox_4d5.setChecked(preferences.getBoolean("5_4d",false));
	}


}
